<template>
	<view class='container'>
		<view class='recent-news'>
			<block v-for='(item, index) in news' :key='index'>
				<view class='news-item' @click='toNewsDetail' :data-id="item.id">
					<view class='news-item-title'>{{ item.title }}</view>
					<view class='news-item-date'>
						{{ item.publishTime }}
					</view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
import { request } from '../../utils/http';
export default {
	data() {
		return {
			news: [],
		}
	},
	onShow: function () {
		//加载公告
		var params = {
			url: "/shop/notice/noticeList",
			method: "GET",
			data: {},
			callBack: (res) => {
				// console.log(res);
				this.news = res.records;
			}
		};
		request(params);
	},
	methods: {
		toNewsDetail: function (e) {
			console.log(e)
			// console.log(id)
			uni.navigateTo({
				url: '/pages/news-detail/news-detail?id=' + e.currentTarget.dataset.id,
			})
			// console.log(id)
		},
	}
}
</script>

<style>
/* pages/recent-news/recent-news.wxss */

.recent-news {
	background: #fff;
}

.recent-news .news-item {
	padding: 20rpx 20rpx 0 20rpx;
	position: relative;
}

.recent-news .news-item::after {
	content: " ";
	width: 100%;
	height: 2rpx;
	background-color: #e1e1e1;
	left: 20rpx;
	display: block;
	position: absolute;
}

.recent-news .news-item .news-item-title {
	font-size: 28rpx;
	text-align: left;
}

.recent-news .news-item .news-item-date {
	font-size: 24rpx;
	color: #999;
	text-align: right;
	margin-top: 10rpx;
	margin-bottom: 20rpx;
}
</style>
